import {request, writeLog} from "../libs/core.js"
export default {
  namespaced: true,  //多出的一行
  state: {
  	data: {
      sysOrg: [],
      sysUser: [],
      sysRole: [],
      sysTags: [],
      sysStar: [],
      appUser: [],
      sysTables: [],
      sysProject: [],
      yesOrNo: {1:"是", 0:"否"},
      verOsType: {1:"Android", 2:"ios"},
      sysLogType: {1:'错误', 2:'警告', 3:'调试', 4:'其他'},
      checkStatus: {0:"待审核", 1:"审核通过", 2:"拒绝通过"},
      saleStatus: {0:"待审核", 1:"上架", 2:"下架"},
      upfileType: {1:'pdf', 2:'chm', 3:'doc', 4:'ppt', 5:'rar', 6:'img', 8:'视频'},
      prjServerRole: {1:'测试', 2:'仿真', 3:'正式'},
      prjOfficerRole: {1:'开发', 2:'策划', 3:'运营', 4:'QA', 5:'运维'},
      sysRoleStatus: {1:'正常', 0:'禁用'},
      sysUserStatus: {1:'正常', 0:'禁用', 2:'锁定'},
      sysUserSex: {1:'男', 2:'女', 0:'保密'},
      sysPayStatus: {0:'待付款',1:'已付款',2:'已退款',3:'退款中',4:'申请退款'},
      sysPayType: {1:'微信',2:'支付宝',3:'QQ',4:'转账'},
      sysShipStatus: {0:'待发货',1:'已发货',2:'签收'}
    }
  },
  mutations: {
    initSet(state, datas) {
		  for (let keys in datas) {
		    state.data[keys] = datas[keys];
		  }
		}
  },
  getters: {
  	list: state => {
      var dicts = {};
      for (var kstr in state.data) {
        dicts[kstr] = [];
        if (Array.isArray(state.data[kstr])) {
          dicts[kstr] = state.data[kstr];
          continue;
        }
        for (var str in state.data[kstr]) {
          (/^[\d]+$/.test(str)) && (str = Number(str));
          dicts[kstr].push([str, state.data[kstr][str]]);
        }
      }
  		return dicts;
  	},
  },
  actions: {
    async shareDicts(context, args) {
      try {
        (!args) && (args = {key: 'sysConfigDicts'});
        const data = await request({url:'/config/loadDicts', data:args, method:'post'});
        context.commit("initSet", data.dataset);
      } catch(e) {
        writeLog(0, e);
      }
      return false;
    },
    async sysOrg(context, args) {
      try {
        const data = await request({url:'/share/doorg', data:args, method:'post'});
        context.commit("initSet", {sysOrg:data.dataset});
      } catch(e) {
        writeLog(0, e);
      }
      return false;
    },
    async sysUser(context, args) {
      try {
        const data = await request({url:'/share/douser', data:args, method:'post'});
        context.commit("initSet", {sysUser:data.dataset});
      } catch(e) {
        writeLog(0, e);
      }
      return false;
    },
    async sysTags(context, args) {
      try {
        const data = await request({url:'/share/dotags', data:args, method:'post'});
        context.commit("initSet", {sysTags:data.dataset});
      } catch(e) {
        writeLog(0, e);
      }
      return false;
    },
    async sysRole(context, args) {
      try {
        const data = await request({url:'/share/dorole', data:args, method:'post'});
        context.commit("initSet", {sysRole:data.dataset});
      } catch(e) {
        writeLog(0, e);
      }
      return false;
    },
    async sysProject(context, args) {
      try {
        const data = await request({url:'/share/doproject', data:args, method:'post'});
        context.commit("initSet", {sysProject:data.dataset});
      } catch(e) {
        writeLog(0, e);
      }
      return false;
    },
    async sysTable(context, args) {
      try {
        const data = await request({url:'/share/dotables', data:args, method:'post'});
        context.commit("initSet", {sysTables:data.dataset});
      } catch(e) {
        writeLog(0, e);
      }
      return false;
    },
		async sysStar(context, args) {
		  try {
		    const data = await request({url:'/ucenter/share/dostar', data:args, method:'post'});
			console.log(data)
		    context.commit("initSet", {sysStar:data.dataset});
		  } catch(e) {
		    writeLog(0, e);
		  }
		  return false;
		},
    async appUser(context, args) {
      try {
        const data = await request({url:'/ucenter/share/douser', data:args, method:'post'});
      console.log(data)
        context.commit("initSet", {appUser:data.dataset});
      } catch(e) {
        writeLog(0, e);
      }
      return false;
    }
  }
}